package com.share.device.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.share.device.domain.Area;
import com.share.device.domain.dto.AreaDto;
import com.share.device.domain.vo.AreaVo;
import com.share.device.mapper.AreaMapper;
import com.share.device.service.AreaService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements AreaService {
    @Autowired
    private AreaMapper areaMapper;
    @Override
    public PageInfo<AreaVo> getAreaList(AreaDto areaDto) {
        PageHelper.startPage(areaDto.getPageNum(), areaDto.getPageSize());
       List<AreaVo> list = areaMapper.getAreaList(areaDto);
        PageInfo<AreaVo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //添加区域
    @Override
    public String add(Area area) {
        if(ObjectUtils.isEmpty(area.getAreaName())){
            throw new RuntimeException("区域名称不能为空");
        }
        if(ObjectUtils.isEmpty(area.getAreaRemarks())){
            throw new RuntimeException("区域描述不能为空");
        }
        areaMapper.insert(area);
        return "添加成功";
    }

    //获取详情
    @Override
    public AreaVo getAreaById(Integer id) {
        if(ObjectUtils.isEmpty(id)){
            throw new RuntimeException("区域id不能为空");
        }
       AreaVo areaVo = areaMapper.getAreaById(id);
        return areaVo;
    }

    //区域详情列表
    @Override
    public List<AreaVo> queryList(Integer id) {
        if(ObjectUtils.isEmpty(id)){
            throw new RuntimeException("区域id不能为空");
        }
        List<AreaVo> list = areaMapper.queryList(id);
        return list;
    }
}
